function F = sys0(x,eC,ell,theta,sigma,pi,rho,eta,i,M,A,B)
% partial default
% partial equilibrium, given eC: eC = 0
q_star = 1;

q0A  = x(1);
q1A  = x(2); % q0A
q0B  = x(3);
q1Bn = x(4);
q1Bd = x(5);
eNn  = x(6); % 0
eNd  = x(7); % 0

a_CA_n = 0;
a_CB_n = 1-ell;
a_NA_n = 0;
a_NB_n = ell;
a_CA_d = 0;
a_CB_d = 1-ell;
a_NA_d = 0;
a_NB_d = ell;

F(1) = ell*(mu(q0A,sigma)-1) - i;
F(2) = - i + ell*(1-pi*a_CB_n*theta/w(q1Bn,sigma,theta)-(1-pi)*a_CB_d*theta/w(q1Bd,sigma,theta))*(mu(q0B,sigma)-1) ...
           + ell*pi*a_CB_n*theta/w(q1Bn,sigma,theta)*(mu(q1Bn,sigma)-1) + ell*(1-pi)*a_CB_d*theta/w(q1Bd,sigma,theta)*(mu(q1Bd,sigma)-1);

F(3) = q0A - q1A;
F(4) = - q1Bn + min(q_star, q0B + ((eC*q0A+(1-eC)*q0B)/M*B/(1-eC)     - (1-theta)*(u(q1Bn,sigma)-u(q0B,sigma)))/theta);
F(5) = - q1Bd + min(q_star, q0B + ((eC*q0A+(1-eC)*q0B)/M*rho*B/(1-eC) - (1-theta)*(u(q1Bd,sigma)-u(q0B,sigma)))/theta);

F(6) = eNn;
F(7) = eNd;

%=========================================================================
% subfunctions
%-------------------------------------------------------------------------
function u = u(q,sigma)
% CRRA utility: u(q)
if sigma < 1
    u = q.^(1-sigma)./(1-sigma);
elseif sigma == 1
    u = log(q);
end

function mu = mu(q,sigma)
% marginal utility: u'(q)
mu = q.^(-sigma);

function w = w(q,sigma,theta)
% w function in effective bargaining power
w = theta + (1-theta)*mu(q,sigma);
